package com.project.class3_30;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Work {
    private static int num = 25;
    public static void main(String[] args) {

        FutureTask<Integer> dz = new FutureTask<Integer>(new Callable<Integer>() {
            private int dzNum;
            @Override
            public Integer call() throws Exception {
                while(num > 0){
                    dzNum ++;
                    num --;

                    Thread.sleep(300);
                }
                return dzNum;
            }
        });

        FutureTask<Integer> xm = new FutureTask<Integer>(new Callable<Integer>() {
            private int xmNum;
            @Override
            public Integer call() throws Exception {
                while(num > 0){
                    xmNum ++;
                    num --;

                    Thread.sleep(500);
                }
                return xmNum;
            }
        });

        new Thread(dz).start();
        new Thread(xm).start();
        try {
            System.out.println("大壮吃了："+dz.get());
            System.out.println("小明吃了："+xm.get());
        }  catch (Exception e) {
            e.printStackTrace();
        }
    }
}
